package com.x.crm.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.x.crm.http.response.car.CarListResponse;
import com.x.erp.model.Car;
import com.x.erp.model.User;
import com.x.erp.rpc.CarRpcService;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/car")
public class CarController {
    @Reference
    private CarRpcService carRpcService;//车辆信息服务

    @RequestMapping(value = "/pagelist", method = {RequestMethod.POST, RequestMethod.GET})
    public CarListResponse getCarList(Car car, HttpServletResponse response, HttpSession session) {
        User loginUser = (User) session.getAttribute(SessionKey.loginUser);
        car.setMarketId(loginUser.getMarketId());
        Integer total = carRpcService.selectCarNum(car);
        List<Car> carList = carRpcService.selectCarList(car);
        CarListResponse carListResponse = new CarListResponse();
        carListResponse.setCars(carList);
        carListResponse.setTotalCnt(total);
        return carListResponse;
    }
}